var demo=function(){
	console.log(1)
}

$(function(){
	console.log("FIN:"+location.href);
})

function initLoading(){
  if($("#loading").length==0){
    $("body").append("<!-- loading -->" +
            "<div class='modal fade' id='loading' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' data-keyboard='false' data-backdrop='static'>" +
            "<div class='modal-dialog' role='document'>" +
            "<div class='modal-content'>" +
            "<div class='modal-header'>" +
            "<h4 class='modal-title' id='myModalLabel'>提示</h4>" +
            "</div>" +
            "<div id='loadingText' class='modal-body'>" +
            "<span class='glyphicon glyphicon-refresh' aria-hidden='true'></span>" +
            "处理中，请稍候。。。" +
            "</div>" +
            "</div>" +
            "</div>" +
            "</div>"
    );
  }
}

function showLoading(text){
	initLoading();
	if(text) $("#loadingText").html(text);
	$("#loading").modal("show");
}
function hideLoading(){
	$("#loading").modal("hide");
}

function postJson(url,data,callback){
	showLoading();
	// Shift arguments if data argument was omitted
	if ( jQuery.isFunction( data ) ) {
		callback = data;
		data = undefined;
	}
	//解包 保持原型
	return $.post(url,data,function(resp,status,xhr){
		if(resp.success){
			callback.call(resp,resp.data,status,xhr);
		}else{
			if(resp.msg) alert(resp.msg);
		}	
	},"json").fail(function(){console.log("fail")})
		.always(function(){
			hideLoading();
		});
}

function initPopup(title,msg){
  if($("#popup").length==0){
    $("body").append("<!-- Popup -->" +
            "<div class='modal fade' id='popup' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' >" +
            "<div class='modal-dialog' role='document'>" +
            "<div class='modal-content'>" +
            "<div class='modal-header'>" +
			"<h4 class='modal-title' id='myModalLabel'>"+title+"</h4>" +
            "</div>" +
            "<div class='modal-body'>" + msg + "</div>" +
            "</div>" +
            "</div>" +
            "</div>"
    );
  }
	else {
		$("#popup").find(".modal-title").html(title);
		//if(msg) String then $(msg);
		$("#popup").find(".modal-body").empty().append(msg);
	}
		return $("#popup");
}

function showPopup(inner,title){
    //var loading = "<span class='glyphicon glyphicon-refresh' aria-hidden='true'></span>处理中，请稍候。。。" ;
	var popup = initPopup("","");
	if(inner) popup.find(".modal-body").empty().append(inner);
	if(title) popup.find(".modal-header").html(title);
	//var option= {keyboard:'false', backdrop:'static'}
	$("#popup").modal("show");
}

function loadPopup(url,title){
	var popup = initPopup("","");
	popup.find(".modal-body").load(url);
	if(title) popup.find(".modal-header").html(title);
	//var option= {keyboard:'false', backdrop:'static'}
	$("#popup").modal("show");
}

function hidePopup(){
	$("#popup").modal("hide");
}
